package stud.mpgame.policyserver;

import org.apache.mina.core.buffer.IoBuffer;
import org.apache.mina.core.session.IoSession;
import org.apache.mina.filter.codec.ProtocolDecoder;
import org.apache.mina.filter.codec.ProtocolDecoderOutput;

public class PolicyDecoder implements ProtocolDecoder
{
    public void decode(IoSession ioSession, IoBuffer ioBuffer, ProtocolDecoderOutput protocolDecoderOutput) throws Exception {
        StringBuffer buffer = new StringBuffer();
        int codePoint;
        boolean zeroByteRead = false;

        do
        {
            codePoint = ioBuffer.get();
            if (codePoint == 0)
            {
                zeroByteRead = true;
            }
            else
            {
                buffer.appendCodePoint( codePoint );
            }
        }
        while (!zeroByteRead && buffer.length() < 100);

        protocolDecoderOutput.write(buffer.toString());
    }

    public void finishDecode(IoSession ioSession, ProtocolDecoderOutput protocolDecoderOutput) throws Exception {

    }

    public void dispose(IoSession ioSession) throws Exception {

    }
}
